import GCJ_CLASS_TYPE = require('./../../common/GCJ_CLASS_TYPE');
import Parser = require('./../base/Parser');
import Serializer = require('./../base/Serializer');
import SJGReplaceItemBase = require('./SJGReplaceItemBase');
import CommonModel = require('./../../common/model/CommonModel');


var CONFIG=require('../../../../common/config');
export  = SJGReplaceItemGroup;

/**
 * 组
 * @author 
 *
 */
class SJGReplaceItemGroup extends SJGReplaceItemBase{
    
    public children: Array<SJGReplaceItemBase>=new Array<SJGReplaceItemBase>(); 
    
    
    public constructor(g?) {
        super(g);

        this.ct = GCJ_CLASS_TYPE.CLASS_TYPE_SJGReplaceItemGroup;
        
    }
    
    // 从json对象(注意不是json字符串)中解析
    public fromJson(jsonObj,versionId) {
        super.fromJson(jsonObj,versionId);
        
        if(jsonObj.children) {
            for(var i=0;i<jsonObj.children.length;i++) {
                var one: SJGReplaceItemBase=<SJGReplaceItemBase> Parser.fromUnknownJson(jsonObj.children[i],versionId,this.getGlobalData());
                if(one) {
                    this.children.push(one);
                }
            }
        }
    }
    
    // 转成json字符串
    public toJson(): string {
        // 去掉父json字符串的头尾
        var superJson = super.toJson();
        superJson = superJson.substr(1,superJson.length - 2);

        var ret = '{';
        ret += superJson;
        
        // children
        ret+=',';
        ret+='"children":';
        ret+='[';
        for(var i=0;i<this.children.length;i++) {
            if(i>0) {
                ret+=',';
            }
            ret+=this.children[i].toJson();
        }
        ret+=']';
        
        ret += '}';
        return ret;
    }
    // 获取对象名称
    public getObjetName(): string {
        return "组";
    }
}//SJG_MARK_END-------------------------
